import * as React from 'react';
import {observer} from 'mobx-react';
import {message} from 'antd';
import {TagBaseFormModal} from '../form/Form';
import {addStore, listStore, searchStore} from '../TagStore';

@observer
export class AddFormModal extends React.Component<any, any> {
    onOk = () => {
        if (addStore.isValid()) {
            addStore.changeConfirmLoading(true);

            addStore.addTag(addStore.getValues())
                .then((data) => {
                    if (data.success) {
                        message.success(data.message, 3);
                        addStore.hide();
                        listStore.refresh(searchStore);
                    } else {
                        message.error(data.message, 3);
                    }

                    addStore.changeConfirmLoading(false);
                })
        } else {
            return false;
        }
    }

    render() {
        return <TagBaseFormModal store={addStore} title="新增" onOk={this.onOk}/>
    }
}
